home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
bisonpcb
/
warshall.c
< prev
Wrap
C/C++ Source or Header
|
1987-09-18
|
3KB
|
126 lines
/* Generate transitive closure of a matrix,
Copyright (C) 1984 Bob Corbett and Free Software Foundation, Inc.
BISON is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the BISON General Public License for full details.
Everyone is granted permission to copy, modify and redistribute BISON,
but only under the conditions described in the BISON General Public
License. A copy of this license is supposed to have been given to you
along with BISON so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
/*
* Port to PC by Whit Gregg
* Nourse, Gregg & Browne, Inc.
* 1 Horizon Road
* Fort Lee, NJ 07024
*/
/****************************************************************************
* Sep 18, 1987
* changed cast from (unsigned *)((unsigned)
* to (unsigned *)((unsigned long)
*
* to allow the use of the MS compact model -- 32 bit addresses
*
* Bill Davis
* 34 Mary Agnes Road
* Framingham, Ma.
* 01701
*/
#include <stdio.h>
#include "machine.h"
#include "func.h"
/* given n by n matrix of bits R, modify its contents
to be the transive closure of what was given. */
void
TC(R, n) /* WG */
unsigned *R;
int n;
{
register unsigned rowsize;
register unsigned mask;
register unsigned *rowj;
register unsigned *rp;
register unsigned *rend;
register unsigned *ccol;
unsigned *relend;
unsigned *cword;
unsigned *rowi;
rowsize = WORDSIZE(n) * sizeof(unsigned);
relend = (unsigned *) ((unsigned long) R + n * rowsize); /* BD */
cword = R;
mask = 1;
rowi = R;
while (rowi < relend) {
ccol = cword;
rowj = R;
while (rowj < relend) {
if (*ccol & mask) {
rp = rowi;
rend = (unsigned *) ((unsigned long) rowj + rowsize); /* BD */
while (rowj < rend)
*rowj++ |= *rp++;
}
else {
rowj = (unsigned *) ((unsigned long) rowj + rowsize); /* BD */
}
ccol = (unsigned *) ((unsigned long) ccol + rowsize); /* BD */
}
mask <<= 1;
if (mask == 0) {
mask = 1;
cword++;
}
rowi = (unsigned *) ((unsigned long) rowi + rowsize); /* BD */
}
}
/* Reflexive Transitive Closure. Same as TC
and then set all the bits on the diagonal of R. */
void
RTC(R, n) /* WG */
unsigned *R;
int n;
{
register unsigned rowsize;
register unsigned mask;
register unsigned *rp;
register unsigned *relend;
TC(R, n);
rowsize = WORDSIZE(n) * sizeof(unsigned);
relend = (unsigned *) ((unsigned long) R + n * rowsize); /* BD */
mask = 1;
rp = R;
while (rp < relend) {
*rp |= mask;
mask <<= 1;
if (mask == 0) {
mask = 1;
rp++;
}
rp = (unsigned *) ((unsigned long) rp + rowsize); /* BD */
}
}